package com.actor;

import com.handler.manager.PacketHandler;
import com.message.TransformationMessages;
import com.util.BeanUtil;

import akka.actor.UntypedActor;

public class ClusterServerWorkerActor extends UntypedActor {

	@Override
	public void onReceive(Object message) throws Exception {
		if (message instanceof TransformationMessages.WorldPacket) {
			TransformationMessages.WorldPacket packet = (TransformationMessages.WorldPacket) message;
			PacketHandler<TransformationMessages.WorldPacket> handler = BeanUtil.snetPacketHandlerManager.getHandler(packet);
			try {
				if(handler!=null){
					Object resPacket = handler.handle(packet);
					if(resPacket!=null){
						getSender().tell(resPacket,getSelf());
					}
				}else{
					System.out.println("error, cmd not found :"+packet.getCmd());
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
		}else{
			unhandled(message);
		}
	}

}
